package JAVATest;

import java.util.Random;
import java.util.Scanner;

/**
 * ClassName:Text_021
 * Package:JAVATest
 * Description:
 * 双色球中奖系统
 *
 * @Author:ZhangXin
 * @Create2023/1/13-22:36
 * @Version:v1.0
 */
public class Text_021 {
    public static void main(String[] args) {
        //生成中奖号码
        int[] arr = creatNUmber();
        System.out.println("===============================");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println("===============================");

        //用户输入彩球号码( 红球 + 蓝球 )
        int[] userInputArr = userInputNumber();
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < userInputArr.length - 1; i++) {
            int redNumber = userInputArr[i];
            for (int j = 0; j < arr.length - 1; j++) {
                if (redNumber == arr[j]) {
                    redCount++;
                    //如果找到了,那么后面的数字就没必要继续比较了
                    //跳出内循环,继续判断下一个红球号码是否中奖
                    break;
                }
            }
        }
        int blueNumber = userInputArr[userInputArr.length - 1];
        if (blueNumber == arr[arr.length - 1]) {
            blueCount++;
        }
        //根据红球个数以及蓝球的个数来判断中奖情况
        if (redCount == 6 && blueCount == 1) {
            System.out.println("恭喜你,中奖1000万!");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("恭喜你,中奖500万");
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你,中奖3000元");
        } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueNumber == 1)) {
            System.out.println("恭喜你,中奖200元");
        } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueNumber == 1)) {
            System.out.println("恭喜你,中奖10元");
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueNumber == 1) || (redCount == 0 && blueNumber == 1)) {
            System.out.println("恭喜你,中奖5元");
        } else {
            System.out.println("谢谢参与！！！");
        }
    }

    public static int[] userInputNumber() {
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; ) {
            System.out.print("请输入第" + (i + 1) + "个红球号码:");
            int redNumber = sc.nextInt();
            if (redNumber >= 1 && redNumber <= 33) {
                boolean flag = contains(arr, redNumber);
                if (!flag) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("当前红球号码已经存在,请从新输入!");
                }
            } else {
                System.out.println("当前红球号码超出范围");
            }
        }
        //用户输入篮球号码
        System.out.print("请输入蓝球号码:");
        int blueNumber = sc.nextInt();
        while (true) {
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("当前篮球号码超出范围!");
            }
        }
        return arr;
    }

    public static int[] creatNUmber() {
        //6个红球，1个蓝球，一共7个球
        int[] arr = new int[7];
        //随机生成号码并添加到数组当中
        //红球：不能重复 1 2 3 4 5 6
        //蓝球：可以和红球重复 5
        //生成红球号码并添加到数组当中
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            int redNumber = r.nextInt(33) + 1;
            boolean flag = contains(arr, redNumber);
            if (!flag) {
                //把红球号码添加到数组当中
                arr[i] = redNumber;
                i++;
            }
        }
        //生成蓝球号码并添加到数组当中
        int blueNumber = r.nextInt(16) + 1;
        arr[arr.length - 1] = blueNumber;
        return arr;
    }

    public static boolean contains(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }

}
